<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增授信信息</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
</style>
</head>
<body class="iframeBody">
<div class="Wrapper">
  <form id="formCrInfo">
     <div class="fieldset1 tabel_col tabel_col_s clearFix">
        <div class="caption">
			<span class="title">授信基础信息 </span>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">融资机构名称</div>
		   <div class="field">
              <span id="fncInsNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">授信编号</div>
		   <div class="field">
              <span id="crId" ></span>
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">授信名称</div>
		   <div class="field">
              <span id="crNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">授信合同号</div>
		   <div class="field">
              <span id="crCtrNo" ></span>
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">授信主体</div>
		   <div class="field">
              <span id="crSbj" ></span>
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">授信额度</div>
		   <div class="field">
              <span id="crLmt" ></span>
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">是否循环授信</div>
		   <div class="field">
              <span id="rvlCr" ></span>
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">货币类型</div>
		   <div class="field">
              <span id="ccyTp" ></span>
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">授信有效期</div>
		   <div class="field">
             <span id="stDt" ></span> 
             <span>&nbsp;至&nbsp;</span>
             <span id="edDt" ></span> 
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">授信状态</div>
		   <div class="field">
             <span id="crStNm" ></span> 
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">是否参与合同审核</div>
		   <div class="field">
             <span id="isPartIn" >
             <c:if test=""></c:if>
             </span> 
           </div>
		</div>
		<div class="fieldBox col_50">
		   <div class="label">是否资管</div>
		   <div class="field">
             <span id="zgFlag" >
             </span> 
           </div>
		</div>
		<div class="fieldBox col_100" id="fileModify">
			<div class="label">资料</div>
			<div class="field">
               	<jsp:include page="../../system/sysUlFilesRec/sysUlFileRecListDetail.jsp" flush="true" >
                  	<jsp:param name="pkId" value="${lgcId }"/>
                  	<jsp:param name="tabNm" value="CST_BSC_INFO"/>
                </jsp:include>
           	</div>
		</div>
		<div class="fieldBox col_100">
		   <div class="label" style="overflow:visible;word-break:break-all">出账条件及到账指标要求</div>
		  <div class="field" style="width:100%" >
			     <textarea name="scmDsc" id="scmDsc" rows="4" class="l-textarea" disabled="disabled"  style="width:100%"></textarea>
		    </div>
		</div>
		<div class="fieldBox col_100">
		   <div class="label">权证资料要求</div>
		   <div class="field" style="width:100%" >
			     <textarea name="rmrk" id="rmrk" rows="4" class="l-textarea" disabled="disabled" style="width:100%"></textarea>
		    </div>
		</div>
	 </div>
	 <div class="fieldset1 tabel_col tabel_col_s clearFix">
       <div class="caption">
		  <span class="title">历史授信信息 </span>
	   </div>
	    <table class="sq-formTable no-border" id="historyCrTable"><!-- class="sq-formTable no-border" -->
          <thead>
            <tr>
               <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">历史授信名称</th>
               <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">历史授信余额</th>
               <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">币种</th>
               <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">是否包含</th>
            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
	</div>
	 <div class="fieldset1 tabel_col tabel_col_s clearFix">
        <div class="caption">
			<span class="title">关联资产信息 </span>
		</div>
        <table id="tableAst" class="sq-formTable no-border"> 
           <thead>
             <tr>
                <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">资产占用种类</th>
                <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">产品编号</th>
                <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">产品名称</th>
                <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">产品额度</th>
                <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">产品余额</th>
                <th class="tbLabel" style="text-align: center;background-color: #e7fef4;">是否可串</th>
             </tr>
           </thead>
           <tbody>
           </tbody>
        </table>
     </div>
  </form>
</div>

<script type="text/javascript">
   $(function() {
	  $("#formCrInfo").ligerForm({
	     validate: true
	  });
	  initData();
	 });
	
   function initData(){
	  var lgcId='${lgcId}';
	  if(!lgcId)  return;
	  var _url = '<%=path%>/rfbase/crbaseinfo/getByLgcId.do';
	  AjaxUtils.ajaxPost(_url, {lgcId:lgcId}, callback);
	}
	
  //新增回调
  function callback(msg){
	if(msg.success == 1){
		 setData(msg.data);//设置数据
	 }else{
		 UIUtils.alertError(msg.info);
	 }
  }
	
	//设置页面数据
 function setData(data){
	 var crBaseInfoVO=data["crBaseInfoVO"];
	 var historyList=data["historyList"];
		$("#crId").html(crBaseInfoVO.crId);
		$("#crNm").html(crBaseInfoVO.crNm);
		$("#crCtrNo").html(crBaseInfoVO.crCtrNo);
		$("#crSbj").html(crBaseInfoVO.crSbjNm);
		$("#crLmt").html(moneyChange(crBaseInfoVO.crLmt));
		$("#rvlCr").html(crBaseInfoVO.rvlCrNm);
		$("#ccyTp").html(crBaseInfoVO.ccyTpNm);
		$("#stDt").html(renderDateChange(crBaseInfoVO.stDt));
		$("#edDt").html(renderDateChange(crBaseInfoVO.edDt));
		$("#rmrk").html(crBaseInfoVO.rmrk);
		$("#fncInsNm").html(crBaseInfoVO.fncInsNm);
		$("#crStNm").html(crBaseInfoVO.crStNm);
		$("#scmDsc").html(crBaseInfoVO.scmDsc);
		$("#isPartIn").html(crBaseInfoVO.isPartInNm);
		$("#zgFlag").html(crBaseInfoVO.zgFlag==1?'是':'否');
	 printAstInfo(crBaseInfoVO);
	 if(historyList!=null&&historyList.length>0){
		 for(var i=0;i<historyList.length;i++){
	 		addHistoryCr(historyList[i]);
		  }
	 }
  };
  
  //显示资产信息
  function printAstInfo(crBaseInfoVO){
	  var astList=crBaseInfoVO.crAstRltvInfoListVO;
		 if(astList!=null&&astList.length>0){
			for(var i in astList){
			 	addAstNext(astList[i]);
			 }
		 }
  }

//CSS样式
        var ltextfield ='position: absolute;'
    				   +' top: 0px;'
    				   +' left: 0px;'
    				   +' height: auto;'
    				   +' line-height: 18px;'
    				   +' padding-left: 0px;'
    				   +' padding-top: 0px;'
    				   +' padding-bottom: 0px;'
    				   +' vertical-align: middle;'
    				   +' background-color: #fff;'
    				   +' width: 174px;'
    				   +' border: 0;'
    				   +' margin: 0;'
    				   +' outline: none;'
    				   +' color: #555555;'
    				   +' border-radius: 4px;';
    	
    	var ltext ='position: relative;'
    				   +' border: 1px solid #e9e9e9;'
    				   +' height: auto;'
    				   +' line-height: 18px;'
    				   +' width: 178px;'
    				   +' border-radius: 4px;';
    				   

    	var field ='display: inline-block;'
    				   +'vertical-align: top;'
    				   +' height: auto;'
    				   +' line-height:1.5em;'
    				   +' border-spacing: 0;'
    				   +' width: 178px;'
    				   +' border-collapse: collapse;';
		
 function addHistoryCr(historyData) {
 	//添加行
     var tableAst = document.getElementById("historyCrTable");
     var  rowIndex = historyCrTable.rows.length;//默认在末尾插入一行
     var row = historyCrTable.insertRow(rowIndex);//在表格的指定插入一行   

     //设置添加行的内容
     var innerHTML='<td style="text-align: center;">'
				   +'<div style="'+ field +'">'  
				   +'<span>'+historyData.crNm+'</span>'  
				   +'</div>'     
				   +'</td>'         
				   +'<td style="text-align: center;">'     
				   +'<div style="'+ field +'">';
			       if(historyData.crBal==null){
					    innerHTML +='<span>0</span>';
				   }else{
					    innerHTML +='<span>'+moneyChange(historyData.crBal)+'</span>';
				   }
		 innerHTML +='</div>'     
				   +'</td>'
				   +'<td style="text-align: center;">'     
				   +'<div style="'+ field +'">'
				   + '<span>'+historyData.ccyTpNm+'</span>'
		           + '</div>'     
			       +'</td>'
			       +'</td>'
				   +'<td style="text-align: center;">'     
				   +'<div style="'+ field +'">';
		     if(historyData.isInc==0){
			    innerHTML +='<span>不包含</span>';
		     }else{
			    innerHTML +='<span>包含</span>';
		     }
		 innerHTML +='</div>'+'</td>';
	 row.innerHTML=innerHTML;	
  }  
 
 function addAstNext(Astdata) {
	 	//添加行
	     var tableAst = document.getElementById("tableAst");
	     var  rowIndex = tableAst.rows.length;//默认在末尾插入一行
	     var row = tableAst.insertRow(rowIndex);//在表格的指定插入一行   
	     
	     //设置添加行的内容
	     var innerHTML ='<td style="text-align: center;">'
					   +'<div style="'+ field +'">' 
					   + '<span>'+Astdata.astNm+'</span>'
					   + '</div>'     
					   +'</td>'         
					   +'<td style="text-align: center;">'     
					   +'<div style="'+ field +'">'  
					   +'<span>'+Astdata.pdId+'</span>' 
					   +'</div>'     
					   +'</td>'
					   +'<td style="text-align: center;">'     
					   +'<div style="'+ field +'">'  
					   +'<span>'+Astdata.pdNm+'</span>' 
					   +'</div>'     
					   +'</td>'
					   +'<td style="text-align: center;">'     
					   +'<div style="'+ field +'">'  
					   +'<span>'+moneyChange(Astdata.useLmt)+'</span>' 
					   +'</div>'     
					   +'</td>'
					   +'<td style="text-align: center;">'     
					   +'<div style="'+ field +'">'  
					   +'<span>'+moneyChange(Astdata.useBal)+'</span>' 
					   +'</div>'     
					   +'</td>'
					   +'<td style="text-align: center;">'     
					   +'<div style="'+ field +'">';
			   if(Astdata.wthrConn==0){
				    innerHTML +='<span>不可串</span>';
			   }else{
				    innerHTML +='<span>可串</span>';
			   }
		innerHTML +='</div>'+'</td>';
		row.innerHTML=innerHTML;			   
  }   

 //格式化时间
 function renderDateChange(value){
	var dateStr = "";
	if(null != value &&  ""!= value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
	}
	return dateStr;
 } 
 
//格式化金额
 function moneyChange(value) { 
		var h = '';
			if(value&&value!="null"){
		    h+=fmoney(value, 2);
			}else{
			h+="0.00";
			}
         return h;
		}
 
 //格式化金额
 function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
</script>

</body>
</html>
